//
//  PBMyOrderCell.m
//  PBHomeDemo
//
//  Created by Playboy on 2018/1/25.
//  Copyright © 2018年 tmkj. All rights reserved.
//

#import "PBMyOrderCell.h"
#import "PBPayNowController.h"
#import "PBPayTypeModel.h"

@interface PBMyOrderCell ()
@property (weak, nonatomic) IBOutlet UILabel *orderNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UIImageView *coverImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *sumPriceLabel;
@property (weak, nonatomic) IBOutlet UIButton *payButton;
@property (nonatomic, strong) PBMyOrderModel *model;

@end

@implementation PBMyOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)refreshWithModel:(PBMyOrderModel *)model {
    self.model = model;
    self.orderNumLabel.text = [NSString stringWithFormat:@"订单号：%@",model.code];
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:model.content[@"cover"]] placeholderImage:nil];
    self.nameLabel.text = model.content[@"name"];
//    self.typeLabel.text = @"五居室-西北卧2-RoomE";
    self.priceLabel.text = [NSString stringWithFormat:@"%@元/月   %@",model.content[@"price"],model.content[@"rentPayment"]];
    self.sumPriceLabel.text = [NSString stringWithFormat:@"¥%@",model.amount];
    if (model.status == 1) {
        self.statusLabel.text = @"待付款";
        self.statusLabel.textColor = [UIColor tm_mainOrignColor];
        self.payButton.hidden = NO;
    }else if (model.status == 2) {
        self.statusLabel.text = @"已完成";
        self.statusLabel.textColor = UIColorWithRGB(139, 139, 139);
        self.payButton.hidden = YES;
    }
}

- (IBAction)payButtonClick:(UIButton *)sender {
    PBPayTypeModel *model = [[PBPayTypeModel alloc] init];
    model.price = self.model.amount;
    
    PBPayNowController *vc = [[PBPayNowController alloc] init];
    vc.payModel = model;
    vc.code = self.model.code;
    vc.creatTime = self.model.createTime;
    [self.jumpVC.navigationController pushViewController:vc animated:YES];
    
    
    
//    [self.jumpVC showHud];
//    NSDictionary *param = @{@"itemId":[NSString stringWithFormat:@"%zd",self.model.bizId]};
//    [TMNetwork requestPostWithParam:param url:@"/order/create" callback:^(TMBaseReqModel *model) {
//        [self.jumpVC hideHud];
//        if (model.code == 200) {
//            [self showAliPayWithCode:model.data];
//        }else {
//            [self showHint:model.message];
//        }
//    }];
}
- (void)showAliPayWithCode:(NSString *)code {
    NSDictionary *param = @{@"code":code,@"payType":@"2"};
    [TMNetwork requestPostWithParam:param url:@"/order/sign" callback:^(TMBaseReqModel *model) {
        if (model.code == 200) {
            [TMNetwork alipayWithParam:model.data[@"data"]];
        }else {
            [self showHint:model.message];
        }
    }];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
